<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta name="screen-orientation" content="portrait">
    <meta name="x5-orientation" content="portrait">
    <title>提前结算明细</title>
    <link rel="stylesheet" href="../../styles/h5/reset.min.css"/>
    <link rel="stylesheet" href="../../styles/h5/errortankuang.css"/>
    <!--以上为公共css样式-->
    <link rel="stylesheet" href="../../styles/h5/index.css"/>
    <link rel="stylesheet" href="../../styles/h5/dropload.css"/>

    <script charset="utf-8" type="text/javascript" src="../../scripts/h5/jquery-1.9.1.min.js"></script>
    <script charset="utf-8" type="text/javascript" src="../../scripts/h5/jquery.modal.js"></script>
    <!--以上为公共js文件-->
</head>
<body>
<div class="zz-pay-detail">
    <!--<ul>
        <li>
            <span class="zz-payDetail-left">订单编号</span>
            <span class="zz-payDetail-right">1111111</span>
        </li>
        <li>
            <span class="zz-payDetail-left">申请时间</span>
            <span class="zz-payDetail-right">啊啊啊</span>
        </li>
        <li>
            <span class="zz-payDetail-left">订单状态</span>
            <span class="zz-payDetail-right zz-color-333">我问问</span>
        </li>
        <li>
            <span class="zz-payDetail-left">金额</span>
            <span class="zz-payDetail-right">对对对</span>
        </li>
        <li>
            <span class="zz-payDetail-left">提前结算服务费</span>
            <span class="zz-payDetail-right">发发发</span>
        </li>
    </ul>-->
</div>

</body>

<script charset="utf-8" type="text/javascript" src="../../scripts/h5/utils.js"></script>
<script charset="utf-8" type="text/javascript" src="../../scripts/h5/index.js"></script>
<script charset="utf-8" type="text/javascript" src="../../scripts/h5/dropload.min.js"></script>

<script charset="utf-8" type="text/javascript">
    var queryURLParameter = utils.queryURLParameter();
    var merId = queryURLParameter.merId;
    // 第几页
    var currentPage = 0;
    // 每页展示20个
    var pageNo = 20;
    var pageNum = 20;
    var data = '';
    var result = '';
    var timer = '';

    function bindHTML() {
        result = '';
        for (var i = 0; i < data.resultList.length; i++) {
            var curData = data.resultList[i];
            var orderState = curData.orderState;
            var orderMsg= "";
            switch (orderState){
            	case 1:
            		orderMsg = "支付中";
            		break;
            	case 3:
            		orderMsg = "支付失败";
            		break;
            	case 4:
            		orderMsg = "交易成功";
            		break;
            	case 11:
            		orderMsg = "待确认";
            		break;
            	case 16:
            		orderMsg = "已受理";
            		break;
            	default:
            		orderMsg = "交易不明";
            }
            
            /* if (orderState == 4) {
                orderMsg = "成功";
            } else if(orderState ==3){
                orderMsg = "失败";
            }else{
                orderMsg = "失败";
            } */
            result += '<ul>';
            result += '<li>';
            result += '<span class="zz-payDetail-left">订单编号</span>';
            result += '<span class="zz-payDetail-right">' + curData.orderId + '</span>';
            result += '</li>';
            result += '<li>';
            result += '<span class="zz-payDetail-left">申请时间</span>';
            result += '<span class="zz-payDetail-right">' + curData.inTime + '</span>';
            result += '</li>';
            result += '<li>';
            result += '<span class="zz-payDetail-left">订单状态</span>';
            result += '<span class="zz-payDetail-right zz-color-333">' + orderMsg + '</span>';
            result += '</li>';
            result += '<li>';
            result += '<span class="zz-payDetail-left">金额</span>';
            result += '<span class="zz-payDetail-right">￥' + curData.origAmt + '</span>';
            result += '</li>';
            result += '<li>';
            result += '<span class="zz-payDetail-left">提前结算服务费</span>';
            result += '<span class="zz-payDetail-right">￥' + curData.comAmt + '</span>';
            result += '</li>';
            if (curData.orderState != 4) {
                result += '<li>';
                result += '<span class="zz-payDetail-left">失败原因</span>';
                result += '<span class="zz-payDetail-right zz-payDetail-maxWidth">' + curData.tradeDesc + '</span>';
                result += '</li>';
            }
            result += '</ul>';
        }
    }

    function loadUp(me){
        // 为了测试，延迟1秒加载
        clearTimeout(timer);
        timer = setTimeout(function () {
            $('.zz-pay-detail').html(result);
			// 每次数据加载完，必须重置
            me.resetload();
            
            if (data.resultList.length < pageNum) {
                //锁定
                me.lock("down");
                //无数据
                //me.noData(true);
                $(".dropload-refresh").html("暂无数据").css("color","#999");
                $(".dropload-noData").html("暂无数据").css("color", "#999");
            } else {
            	//解锁
                me.unlock();
                $(".dropload-refresh").html("↑上拉加载更多").css("color","#333");
                $(".dropload-noData").html("↑上拉加载更多").css("color","#333");
                //有数据
				//me.noData(false);
            }
            
        }, 200);
    }
    
    //上拉加载 ajax回调函数
    function loadDown(me){
		if (data.resultList.length < pageNum) {
        	// 锁定
            me.lock();
            //me.lock("down");
            // 无数据
            me.noData(true);
            //$(".dropload-refresh").html("暂无数据").css("color", "#999");
        } else {
        	me.unlock();
        	me.noData(false);
        }

        // 为了测试，延迟1秒加载
        clearTimeout(timer);
        timer = setTimeout(function () {
            $('.zz-pay-detail').append(result);
            // 每次数据加载完，必须重置

            //me.noData(false);
            me.resetload();
        }, 200);
    }

    function ajaxList(callback,me){
        $.ajax({
            type: 'GET',
            url: utils.ajaxUrl()+"h5/queryPayController/queryEarlyPay",
            data: {
                pageNo: pageNo,
                currentPage: currentPage,
                merId: merId
            },
            dataType: 'json',
            success: function (res) {
                console.log(res);
                //var data = JSON.parse(res);
                data = res;
                if (data.retCode == "0000") {
                    bindHTML();
                    callback(me);
                } else {
                    me.lock("down");
                	me.noData(true);
                    utils.newModalPrompt(data.retMsg);
                    me.resetload();
                }
            },
            error: function (xhr, type) {
                utils.newModalPrompt("失败");
 				
                me.noData(true);
                // 即使加载出错，也得重置
                me.resetload();
                me.lock("down");
            }
        });
    }

    $(function () {
        // dropload
        $('body').dropload({
            scrollArea: window,
            domUp: {
                domClass: 'dropload-up',
                domRefresh: '<div class="dropload-refresh">↓下拉刷新</div>',
                domUpdate: '<div class="dropload-update">↑释放更新</div>',
                domLoad: '<div class="dropload-load"><span class="loading"></span>加载中...</div>'
            },
            domDown: {
                domClass: 'dropload-down',
                domRefresh: '<div class="dropload-refresh">↑上拉加载更多</div>',
                domLoad: '<div class="dropload-load"><span class="loading"></span>加载中...</div>',
                domNoData: '<div class="dropload-noData">暂无数据</div>'
            },
            // 下拉刷新
            loadUpFn: function (me) {
                // 第一页
                currentPage = 1;

                ajaxList(loadUp,me);
            },
            // 上拉加载 和初始化
            loadDownFn: function (me) {
                // 页数累加
                currentPage++;
                //ajax
                ajaxList(loadDown,me);
            },
            distance:50,
            threshold:3
        });
    });


</script>
</html>